package com.ccb.lms.dao;

import java.sql.SQLException;
import java.util.List;

import com.ccb.lms.model.LibraryAdmin;
import com.ccb.lms.util.BasePage;
import com.ibatis.sqlmap.client.SqlMapClient;

public class LibraryAdminDAO implements ILibraryAdminDAO {
	private SqlMapClient sqlMapClient = null;

	public SqlMapClient getSqlMapClient() {
		return sqlMapClient;
	}

	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}
	
	public boolean insertLibraryAdmin(LibraryAdmin libraryAdmin) throws SQLException {
		sqlMapClient.insert("libraryAdmin.insertLibraryAdmin", libraryAdmin);
		return true;
	}

	public boolean deleteLibraryAdmin(Integer libraryAdminNO) throws SQLException {
		sqlMapClient.delete("libraryAdmin.deleteLibraryAdmin", libraryAdminNO);
		return true;
	}

	public boolean updateLibraryAdmin(LibraryAdmin libraryAdmin) throws SQLException {
		sqlMapClient.update("libraryAdmin.updateLibraryAdmin", libraryAdmin);
		return true;
	}

	@SuppressWarnings("unchecked")
	public List<LibraryAdmin> getAllLibraryAdmins() throws SQLException {
		return sqlMapClient.queryForList("libraryAdmin.getAlllibraryAdmins");
	}

	public LibraryAdmin getLibraryAdminByID(String libraryAdminID) throws SQLException {	
		return (LibraryAdmin) sqlMapClient.queryForObject("libraryAdmin.getLibraryAdminByID", libraryAdminID);
	}

	public int getLibraryAdminCount() throws SQLException {
		return (Integer) sqlMapClient.queryForObject("libraryAdmin.recordCount");
	}

	public BasePage getBasePage(int currentPage, int showRecordNum)
			throws SQLException {
		return new BasePage(currentPage, getLibraryAdminCount(), showRecordNum);
	}

	@SuppressWarnings("unchecked")
	public List<LibraryAdmin> getLibraryAdminByPage(BasePage basePage) throws SQLException {
		return sqlMapClient.queryForList("libraryAdmin.getLibraryAdminByPage", basePage);
	}

	public boolean isLogin(LibraryAdmin libraryAdmin) throws SQLException {
		if (sqlMapClient.queryForObject("libraryAdmin.checklibraryAdmin", libraryAdmin) != null) {
			return true;
		}
		return false;
	}


}
